#!/bin/sh

###############################################
# File:         common info 线上测试打包脚本
# Description:  验证给定的路径，
#               若存在，则返回1；
#               否则返回0，并邮件告知
#
###############################################

#
# 定义变量
#
#---------------------------------------------
#app=0;         	# app_need_to_check
#build=0;         	# build_js
#deploy=0;          # deploy_web
#---------------------------------------------

while getopts "g:" opt
do 
    case $opt in
        
		g) #set option "g"
            branch=$OPTARG
            ;;				
        *)
            echo "-$opt not recognized"
            ;;
    esac
done


# ---
declare path=$(cd `dirname $0`; pwd)
echo "current path is  :" ${path}  

# appName

declare appName="common-info";
declare appPath=${path}/${appName}
cd ${appPath}

#echo "git pull start..."
if [ -n "${branch}" ]; then
  echo "git 分支 ${branch}"
	git checkout ${branch}
  git pull origin ${branch}
  else
  echo "git 分支 master"
  git checkout master
  git pull origin master
fi


declare DEPLOY_DIR="/home/apps_test/archv";
declare zipFile=${appName}-server-1.0-SNAPSHOT-cli.tar.gz;
declare source_zipfile=${appPath}/server/target/${zipFile}

mvn clean install
    declare server_sub_dir="server";
	 cd ${server_sub_dir}
    echo "assembly start..."

mvn  assembly:assembly -q


if [ ! -f "${source_zipfile}" ]; then
  echo "zip文件不存在,${source_zipfile},exit"
  exit 0;
fi

declare DEPLOY_APP_PATH="${DEPLOY_DIR}/${appName}";

declare deploy_arch_path=${DEPLOY_APP_PATH};

declare deploy_zipfile=${deploy_arch_path}/${zipFile}

echo "推送到远程目录 122.114.80.44:${deploy_arch_path}"
#scp ${source_zipfile} root@122.114.80.44:${deploy_arch_path}

cp ${source_zipfile} ${deploy_arch_path} ;

